<?php
require_once 'config.php';
require_once 'function.php';
require_once 'class/Mysql.class.php';


$kid = post('kid');
$type = post('type');
$table = post('table');
$tr_arr = $_POST['tr'];

//print_r( $tr_arr );exit;

//过滤操作
foreach( $tr_arr as $k=>$v ){
	$tr_arr[$k] = f( $v );
}


switch( $type ){
	case 'article':
		$ret = d('topic_article', 'ar_id');
	break;
	case 'table':
		$ret = d('Table_'.$table, 'D_ID');
	break;
	case 'product':
		$ret = d('product', 'product_id');
	break;
	case 'won_product':
		$ret = d('won_product', 'id');
	break;
	case 'feature':
		$ret = d('feature', 'feature_id');
	break;
	case 'product_page':
		$ret = d('product_page', 'page_id');
	break;
	case 'category':
		$ret = d('category', 'cat_id');
	break;
}

echo '<script type="text/javascript">parent.'.( $ret ? 'ok()' : 'no()').';</script>';



function d( $table, $field ){
	global $kid, $tr_arr;
	$db = new Mysql();
	
	$ret = $db->update($table, $tr_arr, $field.'='.$kid);
	
	if( $ret ){
		$db->update($table, array('is_translate'=>1), $field.'='.$kid);
	}
	return $ret;
}


function f( $html ){
	global $product_name;
	
	//return $html;
	
	//去掉google或微软翻译产生的多余<font>或</font>标签
	$html = preg_replace('|<[/]?font>|is', '', $html);
	//还原原页面中的font标签
	$html = str_replace(array('<s-font','</s-font>'), array('<font','</font>'), $html );
	
	//取消html页面中的<!--[--和--]-->注释
	$html = str_replace('<!--[--', '', $html );
	$html = str_replace('--]-->', '', $html );
	
	//调换数字与美元符顺序
	$html = preg_replace('/([\d]+),([\d]+)[\s]*\$/', '$$1.$2', $html);
	//去掉空格，逗号改成点
	$html = preg_replace('/\$[\s]*([\d]+),([\d]+)/', '$$1.$2', $html);
	
	
	//还原过滤词
	foreach( $product_name as $k=>$v ){
		$html = str_replace( '0-'.$k.'-0', $v, $html );
	}

	return $html;
}


